﻿using MengLin.OOP.DesignPattern.Strategy.WarriorFight.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.Strategy.WarriorFight
{
    /// <summary>
    /// 环境类
    /// 相当于武士类
    /// </summary>
    public class Context
    {
        private IStrategy _iStrategy;

        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="iStrategy"></param>
        public Context(IStrategy iStrategy)
        {
            _iStrategy = iStrategy;
        }

        /// <summary>
        /// 设置武器（方法注入）
        /// </summary>
        /// <param name="iStrategy"></param>
        public void SetWeapon(IStrategy iStrategy)
        {
            _iStrategy = iStrategy;
        }

        public IStrategy Strategy
        {
            get { return _iStrategy; }
            set { _iStrategy = value; }
        }

        /// <summary>
        /// 战斗
        /// </summary>
        public void Fight()
        {
            _iStrategy.Fight();
        }
    }
}
